/*
 * Copyright 2024 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.pajamas.starter.integration.spring.caching;

import org.pajamas.protocol.Builder;
import org.redisson.spring.cache.CacheConfig;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;

/**
 * @author william
 * @since 2024/4/2
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Getter
public class RedissonCacheConfigBuilder extends CacheConfig implements Builder<CacheConfig> {
    private String name;

    private RedissonCacheConfigBuilder() {
    }

    public static RedissonCacheConfigBuilder newBuilder() {
        return new RedissonCacheConfigBuilder();
    }

    public RedissonCacheConfigBuilder name(String name) {
        this.name = name;
        return this;
    }

    public RedissonCacheConfigBuilder ttL(long ttl) {
        this.setTTL(ttl);
        return this;
    }

    public RedissonCacheConfigBuilder maxIdleTime(long maxIdleTime) {
        this.setMaxIdleTime(maxIdleTime);
        return this;
    }

    public RedissonCacheConfigBuilder maxSize(int maxSize) {
        this.setMaxSize(maxSize);
        return this;
    }

    @Override
    public CacheConfig build() {
        CacheConfig config = new CacheConfig();
        config.setTTL(this.getTTL());
        config.setMaxIdleTime(this.getMaxIdleTime());
        config.setMaxSize(this.getMaxSize());
        return config;
    }
}
